//
//  GConnection.h
//  Genesis
//
//  Created by Kristoffer Andersen on 13/03/09.
//  Copyright 2009 Kristoffer Andersen. All rights reserved.
//
//  This file is part of Genesis.
//  
//  Genesis is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//  
//  Genesis is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with Genesis.  If not, see <http://www.gnu.org/licenses/>.

#import <Cocoa/Cocoa.h>
#import "shhTunnel.h"
#import "tunBonjour.h"
#import "SSHSession.h"


@interface GConnection : NSObject <NSCoding, SSHPasswordDelegate> {
	
	//delegate object
	id delegate;
	
	//Identifers
	NSString *connectionName;
	
	//Connection properties
	NSString *tunnelHost;
	unsigned int tunnelPort;
	NSString *forwardHost;
	unsigned int forwardPort;
	NSString *localHost;
	unsigned int localPort;
	
	
	//Bonjour properties
	bool useBonjour;
	NSString *serviceName;
	NSString *serviceType;
	NSString *serviceRecord;
	//unsigned int servicePort; //Should be the same as localPort
	
	shhTunnel *tunnel;
	tunBonjour *bService;
	
	//Authcentication
	NSString *tunnelUsername;
	//NSString *tunnelPassword; //Not secure! - Use Keychain
	
	//Status
	bool connecting;
	bool connected;
	bool prepared;
	bool interrupted;
	NSString *error;
	bool BonjourRunning;
	
	//Console cache
	NSMutableString *consoleCache;

    SSHSession *session;

    NSCondition *flag;
    NSString *password;
	
}
/* // ----- Only for Leopard SDK (10.5) ------
@property(readwrite, retain) NSString tunnelHost;
@property(readwrite, retain) NSString forwardHost;
@property(readwrite, retain) NSString localHost;
@property(readwrite, retain) NSString serviceName;

@property(readwrite, assign) int tunnelPort;
@property(readwrite, assign) int forwardPort;
@property(readwrite, assign) int localPort;
@property(readwrite, assign) bool useBonjour;

@property(readwrite, retain) NSString *tunnelUsername;
@property(readwrite, retain) NSString *tunnelPassword;
*/
@property(readwrite, retain) id delegate;
@property (readonly) NSCondition *flag;
@property (readwrite, retain) NSString *password;

+(NSString*) getv4Address:(NSHost*)host;

-(id)init;

////////////////////////////////////////////////////////////////
//// Setter accessors
-(void)setConnectionName:(NSString *)newName;
-(void)setTunnelHost:(NSString *)newTunnelHost;
-(void)setTunnelPort:(unsigned int)newTunnelPort;
-(void)setForwardHost:(NSString *)newForwardHost;
-(void)setForwardPort:(unsigned int)newForwardPort;
-(void)setLocalHost:(NSString *)newLocalHost;
-(void)setLocalPort:(unsigned int)newLocalPort;
-(void)setUseBonjour:(bool)newValue;
-(void)setServiceType:(NSString *)newServiceType;
-(void)setServiceRecord:(NSString *)newServiceRecord;
-(void)setServiceName:(NSString *)newServiceName;
-(void)setTunnelUsername:(NSString *)newUsername;

////////////////////////////////////////////////////////////////
//// Getter Accessors
-(NSString *)connectionName;
-(NSString *)tunnelHost;
-(unsigned int)tunnelPort;
-(NSString *)forwardHost;
-(unsigned int)forwardPort;
-(NSString *)localHost;
-(unsigned int)localPort;
-(bool)useBonjour;
-(NSString *)serviceName;
-(NSString *)serviceType;
-(NSString *)serviceRecord;
-(NSString *)tunnelUsername;
-(bool)prepared;
-(bool)connected;
-(bool)interrupted;
-(bool)connecting;
-(NSMutableString *)console;

////////////////////////////////////////////////////////////////
//// Connection Methods

-(int)prepareConnection;
-(void)createConnection;
-(void)terminateConnection;

@end
